<template>
  <section>
    <el-form label-width="100px">
      <el-form-item label="类型名称：">
        <el-input size="mini" v-model="type.name" style="width:50%"></el-input>
      </el-form-item>
      <el-form-item label="业务类型：">
        <el-select size="mini" v-model="type.businessTypeCode">
          <el-option v-for="businessType in businessTypeList" :key="businessType.id" :value="businessType.code" :label="businessType.name"/>
        </el-select>
      </el-form-item>
      <el-form-item label="基本属性：">
        <sel-prop :typeData="type.data"/>
      </el-form-item>
      <el-form-item label="">
        <el-button size="mini" type="success" @click="confirmBtn(type)">{{type.id?'保存':'新建'}}</el-button>
      </el-form-item>
    </el-form>
  </section>
</template>

<script>
  import selProp from '@/common/selProp'
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import errHandler from '@/assets/errHandler.js'
  export default {
    name: "newType",
    props:['type'],
    components:{selProp},
    data() {
      return {
        businessTypeList:null,
        propList:[{key:'地址',val:false,code:'needAddress'},{key:'用户',val:false,code:'needCustomerId'}],
      }
    },
    created() {
      this.getBusinessType()
    },
    computed: {
      ...mapGetters(['department']),
    },
    watch:{
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      getBusinessType(){
        this.fetch({name:"getBusinessTypeList"})
          .then(res=>{
            this.businessTypeList=res
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      makeDataUi(obj){
        this.propList.forEach(prop=>{
          prop.val=false//初始化一下
          for(let key in obj){
            if(prop.code === key){
              prop.val=obj[key]
            }
          }
        })
      },
      confirmBtn(e){
        this.$emit('confirm',e)
      },
    }
  }
</script>

<style scoped>

</style>
